﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CommonFramework.Utility;
using Back.Xinkui.Common;
using Back.Xinkui.Entity.Advert;
using Back.Xinkui.DataAccess.Advert;

public partial class advertSpaceList : System.Web.UI.Page
{
    protected List<AdvertSpaceEntity> AdvertSpaceList { get; set; }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            AspNetPager1.PageSize = ddlPageCount.SelectedValue.ToType<int>(10);
            BindAdvertSpaceList();
        }
    }

    protected void BindAdvertSpaceList()
    {
        string where = "";
        if (!string.IsNullOrEmpty(this.txtSpaceNo.Text.Trim()))
        {
            where += " AND a.SpaceNo Like '%" + this.txtSpaceNo.Text.Trim() + "%'";
        }
        if (!string.IsNullOrEmpty(this.txtSpaceName.Text.Trim()))
        {
            where += " AND a.SpaceName Like '%" + this.txtSpaceName.Text.Trim() + "%'";
        }
        if (!string.IsNullOrEmpty(this.txtWidth.Text.Trim()))
        {
            where += " AND a.Width = " + this.txtWidth.Text.Trim();
        }
        if (!string.IsNullOrEmpty(this.txtHeight.Text.Trim()))
        {
            where += " AND a.Height = " + this.txtHeight.Text.Trim();
        }
        if (!string.IsNullOrEmpty(this.ddpSpaceType.SelectedValue))
        {
            where += " AND a.SpaceType = " + this.ddpSpaceType.SelectedValue;
        }

        Pager page = new Pager { PageIndex = AspNetPager1.CurrentPageIndex, PageSize = AspNetPager1.PageSize };

        AdvertSpaceList = AdvertDataAccess.GetAdvertSpaceList(where, page);

        AspNetPager1.RecordCount = page.TotalCount;
    }

    protected void btnSerach_Click(object sender, EventArgs e)
    {
        BindAdvertSpaceList();
    }

    /// <summary>
    /// 翻页
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        BindAdvertSpaceList();
    }

    /// <summary>
    /// 切换每页显示数据行数
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ddlPageCount_SelectedIndexChanged(object sender, EventArgs e)
    {
        AspNetPager1.PageSize = Convert.ToInt32(ddlPageCount.SelectedValue);
        BindAdvertSpaceList();
    }
}